package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.HatchetSystemConfig;
import com.ruoyi.system.service.IHatchetSystemConfigService;

/**
 * 系统配置 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-03-16
 */
@Controller
@RequestMapping("/system/hatchetSystemConfig")
public class HatchetSystemConfigController extends BaseController
{
    private String prefix = "system/hatchetSystemConfig";
	
	@Autowired
	private IHatchetSystemConfigService hatchetSystemConfigService;
	
	@RequiresPermissions("system:hatchetSystemConfig:view")
	@GetMapping()
	public String hatchetSystemConfig()
	{
	    return prefix + "/hatchetSystemConfig";
	}
	
	/**
	 * 查询系统配置列表
	 */
	@RequiresPermissions("system:hatchetSystemConfig:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(HatchetSystemConfig hatchetSystemConfig)
	{
		startPage();
        List<HatchetSystemConfig> list = hatchetSystemConfigService.selectHatchetSystemConfigList(hatchetSystemConfig);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出系统配置列表
	 */
	@RequiresPermissions("system:hatchetSystemConfig:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HatchetSystemConfig hatchetSystemConfig)
    {
    	List<HatchetSystemConfig> list = hatchetSystemConfigService.selectHatchetSystemConfigList(hatchetSystemConfig);
        ExcelUtil<HatchetSystemConfig> util = new ExcelUtil<HatchetSystemConfig>(HatchetSystemConfig.class);
        return util.exportExcel(list, "hatchetSystemConfig");
    }
	
	/**
	 * 新增系统配置
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存系统配置
	 */
	@RequiresPermissions("system:hatchetSystemConfig:add")
	@Log(title = "系统配置", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(HatchetSystemConfig hatchetSystemConfig)
	{		
		hatchetSystemConfig.setId(StringUtils.randomUUID());
		hatchetSystemConfig.setCreateTime(new Date());
		hatchetSystemConfig.setCreateUserId(getUserId()+"");
		return toAjax(hatchetSystemConfigService.insertHatchetSystemConfig(hatchetSystemConfig));
	}

	/**
	 * 修改系统配置
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		HatchetSystemConfig hatchetSystemConfig = hatchetSystemConfigService.selectHatchetSystemConfigById(id);
		mmap.put("hatchetSystemConfig", hatchetSystemConfig);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存系统配置
	 */
	@RequiresPermissions("system:hatchetSystemConfig:edit")
	@Log(title = "系统配置", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(HatchetSystemConfig hatchetSystemConfig)
	{		
		hatchetSystemConfig.setUpdateTime(new Date());
		hatchetSystemConfig.setUpdateUserId(getUserId()+"");
		return toAjax(hatchetSystemConfigService.updateHatchetSystemConfig(hatchetSystemConfig));
	}
	
	/**
	 * 删除系统配置
	 */
	@RequiresPermissions("system:hatchetSystemConfig:remove")
	@Log(title = "系统配置", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(hatchetSystemConfigService.deleteHatchetSystemConfigByIds(ids));
	}
	

    /**
     * 校验配置代码唯一
     */
    @PostMapping("/checkConfigCode")
    @ResponseBody
    public String checkConfigCodeUnique(HatchetSystemConfig hatchetSystemConfig)
    {
        return hatchetSystemConfigService.checkConfigCodeUnique(hatchetSystemConfig.getConfigCode());
    }

	
}
